package com.gsdse.service.impl;

import com.alibaba.excel.EasyExcel;
import com.gsdse.dao.ApplyDao;
import com.gsdse.pojo.ApplyExcel;
import com.gsdse.pojo.ReturnData;
import com.gsdse.service.ExportExcelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;


@Service
public class ExportExcelServiceImpl implements ExportExcelService {
    @Autowired
    ApplyDao applyDao;

    @Override
    public ReturnData getDepartmentApply(String deptId, String startTime, String endTime, HttpServletResponse response) throws IOException {

        List<ApplyExcel> applyExcelList=applyDao.getDepartmentApplyExcel(deptId,startTime,endTime);
        String fileName="D:\\kjApply\\"+"apply"+System.currentTimeMillis()+".xls";
        EasyExcel.write(fileName, ApplyExcel.class).sheet("投递记录").doWrite(applyExcelList);
        ReturnData returnData = new ReturnData();
        returnData.setCode(0);
        returnData.setMsg("导出成功，请等待下载......");
        return returnData;
    }
}
